/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aggredi.englishlearn.logic;

import java.io.IOException;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Serik_Idrissov
 */
public class RandomProposal {

    public void rand() throws Exception {
        FileAccess access = new FileAccessImpl();
        List<String> list = null;
        try {
            list = access.getProposal("proposal.txt");
        } catch (IOException ex) {
            Logger.getLogger(RandomProposal.class.getName()).log(Level.SEVERE, null, ex);
        }
        ArrayList<String> ru = new ArrayList<>();
        ArrayList<String> en = new ArrayList<>();
        for (String s : list) {
            String[] args = s.split(";");
            if (args.length > 2) {
                throw new Exception("Не валидный файл");
            }
            ru.add(args[0]);
            en.add(args[1]);
        }
        Random random = new Random();
        String propos = "";
        String request = "";
        Scanner scan = new Scanner(System.in);
        int right = 0;
        for (int i = 0; i < 20; i++) {
            int r = random.nextInt(list.size());
            propos = list.get(r);
            System.out.println(propos);
            request = scan.nextLine();
            if (en.get(r).equals(request)) {
                right++;
            }
        }
        System.out.println("Правильных " + right);
    }
}
